package com.onesports.intelligent.k12.polarlight.schedule;

import com.onesports.intelligent.k12.polarlight.service.schedulejob.ScheduleJobService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 定时任务
 *
 * @author clw
 * @date 2022-07-19 10:30:06
 */
@Component
@Slf4j
public class ScheduleJob {

    @Resource
    private ScheduleJobService scheduleJobService;

    /**
     * 课程到期
     */
    @Scheduled(cron = "${job.cron.expire-course}")
    public void courseExpires(){
        scheduleJobService.courseExpires();
    }

    /**
     * 满足最低人数要求
     */
    @Scheduled(cron = "${job.cron.meet-min-num}")
    public void minNum(){
        scheduleJobService.minNum();
    }

    /**
     * spelling_class_period 表符合条件的更新为已过期
     */
    @Scheduled(cron = "${job.cron.expire-spell-class-period}")
    public void spellingClassPeriod(){
        scheduleJobService.spellingClassPeriod();
    }


    /**
     * 定时添加考勤 每分钟
     */
    @Scheduled(cron = "${job.cron.add-attendance}")
    public void addAttendance(){
        scheduleJobService.addStudentAttendance(new Date());
    }

    /**
     * 定时判断上课提醒 每分钟
     */
    @Scheduled(cron = "${job.cron.class-remind}")
    public void classRemind(){
        scheduleJobService.classRemind();
    }

    /**
     * 机构到期停用
     */
    @Scheduled(cron = "${job.cron.expire-stop-use}")
    public void expireStopUse() {
        scheduleJobService.batchUpdateStatus();
    }

    /**
     * 订单定时确认支付
     */
    @Scheduled(cron = "${job.cron.expire-confirm-order}")
    public void expireConfirmOrder() {
        scheduleJobService.batchConfirmOrder();
    }


    /**
     * 到期对考勤中的班级课表进行结课
     */
    @Scheduled(cron = "0 */1 * * * ?")
    public void expireFinishClass(){
        scheduleJobService.expireFinishClass(new Date());
    }


    /**
     * 首页看板数据 半小时一次
     */
//    @Scheduled(cron = "0 0/1 * * * ? ")
    @Scheduled(cron = "${job.cron.home-page}")
    public void homePage(){
        scheduleJobService.homePage(new Date());
    }


}
